<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QTextDocumentWriter Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QTextDocumentWriter Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QTextDocumentWriter class provides a format-independent
interface for writing a <a href="qtextdocument.html">QTextDocument</a> to files or other devices.
<a href="#details">More...</a></p>

<h3>Methods</h3><ul><li><div class="fn" /><b><a href="qtextdocumentwriter.html#QTextDocumentWriter">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qtextdocumentwriter.html#QTextDocumentWriter-2">__init__</a></b> (<i>self</i>, QIODevice&#160;<i>device</i>, QByteArray&#160;<i>format</i>)</li><li><div class="fn" /><b><a href="qtextdocumentwriter.html#QTextDocumentWriter-3">__init__</a></b> (<i>self</i>, QString&#160;<i>fileName</i>, QByteArray&#160;<i>format</i>&#160;=&#160;QByteArray())</li><li><div class="fn" />QTextCodec <b><a href="qtextdocumentwriter.html#codec">codec</a></b> (<i>self</i>)</li><li><div class="fn" />QIODevice <b><a href="qtextdocumentwriter.html#device">device</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qtextdocumentwriter.html#fileName">fileName</a></b> (<i>self</i>)</li><li><div class="fn" />QByteArray <b><a href="qtextdocumentwriter.html#format">format</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qtextdocumentwriter.html#setCodec">setCodec</a></b> (<i>self</i>, QTextCodec&#160;<i>codec</i>)</li><li><div class="fn" /><b><a href="qtextdocumentwriter.html#setDevice">setDevice</a></b> (<i>self</i>, QIODevice&#160;<i>device</i>)</li><li><div class="fn" /><b><a href="qtextdocumentwriter.html#setFileName">setFileName</a></b> (<i>self</i>, QString&#160;<i>fileName</i>)</li><li><div class="fn" /><b><a href="qtextdocumentwriter.html#setFormat">setFormat</a></b> (<i>self</i>, QByteArray&#160;<i>format</i>)</li><li><div class="fn" />bool <b><a href="qtextdocumentwriter.html#write">write</a></b> (<i>self</i>, QTextDocument&#160;<i>document</i>)</li><li><div class="fn" />bool <b><a href="qtextdocumentwriter.html#write-2">write</a></b> (<i>self</i>, QTextDocumentFragment&#160;<i>fragment</i>)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />list-of-QByteArray <b><a href="qtextdocumentwriter.html#supportedDocumentFormats">supportedDocumentFormats</a></b> ()</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QTextDocumentWriter class provides a format-independent
interface for writing a <a href="qtextdocument.html">QTextDocument</a> to files or other
devices.</p>
<p>To write a document, construct a QTextDocumentWriter object with
either a file name or a device object, and specify the document
format to be written. You can construct a writer and set the format
using <a href="qtextdocumentwriter.html#setFormat">setFormat</a>()
later.</p>
<p>Call <a href="qtextdocumentwriter.html#write">write</a>() to
write the document to the device. If the document is successfully
written, this function returns true. However, if an error occurs
when writing the document, it will return false.</p>
<p>Call <a href="qtextdocumentwriter.html#supportedDocumentFormats">supportedDocumentFormats</a>()
for a list of formats that QTextDocumentWriter can write.</p>
<p>Since the capabilities of the supported output formats vary
considerably, the writer simply outputs the appropriate subset of
objects for each format. This typically includes the formatted text
and images contained in a document.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QTextDocumentWriter" />QTextDocumentWriter.__init__ (<i>self</i>)</h3><p>Constructs an empty <a href="qtextdocumentwriter.html">QTextDocumentWriter</a> object. Before
writing, you must call <a href="qtextdocumentwriter.html#setFormat">setFormat</a>() to set a
document format, then <a href="qtextdocumentwriter.html#setDevice">setDevice</a>() or <a href="qtextdocumentwriter.html#setFileName">setFileName</a>().</p>


<h3 class="fn"><a name="QTextDocumentWriter-2" />QTextDocumentWriter.__init__ (<i>self</i>, <a href="qiodevice.html">QIODevice</a>&#160;<i>device</i>, <a href="qbytearray.html">QByteArray</a>&#160;<i>format</i>)</h3><p>Constructs a <a href="qtextdocumentwriter.html">QTextDocumentWriter</a> object to write
to the given <i>device</i> in the document format specified by
<i>format</i>.</p>


<h3 class="fn"><a name="QTextDocumentWriter-3" />QTextDocumentWriter.__init__ (<i>self</i>, QString&#160;<i>fileName</i>, <a href="qbytearray.html">QByteArray</a>&#160;<i>format</i>&#160;=&#160;QByteArray())</h3><p>Constructs an <a href="qtextdocumentwriter.html">QTextDocumentWriter</a> object that will
write to a file with the name <i>fileName</i>, using the document
format specified by <i>format</i>. If <i>format</i> is not
provided, <a href="qtextdocumentwriter.html">QTextDocumentWriter</a> will detect the
document format by inspecting the extension of <i>fileName</i>.</p>


<h3 class="fn"><a name="codec" /><a href="qtextcodec.html">QTextCodec</a> QTextDocumentWriter.codec (<i>self</i>)</h3><p>Returns the codec that is currently assigned to the writer.</p>
<p><b>See also</b> <a href="qtextdocumentwriter.html#setCodec">setCodec</a>().</p>


<h3 class="fn"><a name="device" /><a href="qiodevice.html">QIODevice</a> QTextDocumentWriter.device (<i>self</i>)</h3><p>Returns the device currently assigned, or 0 if no device has
been assigned.</p>
<p><b>See also</b> <a href="qtextdocumentwriter.html#setDevice">setDevice</a>().</p>


<h3 class="fn"><a name="fileName" />QString QTextDocumentWriter.fileName (<i>self</i>)</h3><p>If the currently assigned device is a <a href="qfile.html">QFile</a>, or if <a href="qtextdocumentwriter.html#setFileName">setFileName</a>() has been
called, this function returns the name of the file to be written
to. In all other cases, it returns an empty string.</p>
<p><b>See also</b> <a href="qtextdocumentwriter.html#setFileName">setFileName</a>() and
<a href="qtextdocumentwriter.html#setDevice">setDevice</a>().</p>


<h3 class="fn"><a name="format" /><a href="qbytearray.html">QByteArray</a> QTextDocumentWriter.format (<i>self</i>)</h3><p>Returns the format used for writing documents.</p>
<p><b>See also</b> <a href="qtextdocumentwriter.html#setFormat">setFormat</a>().</p>


<h3 class="fn"><a name="setCodec" />QTextDocumentWriter.setCodec (<i>self</i>, <a href="qtextcodec.html">QTextCodec</a>&#160;<i>codec</i>)</h3><p>Sets the codec for this stream to <i>codec</i>. The codec is
used for encoding any data that is written. By default, <a href="qtextdocumentwriter.html">QTextDocumentWriter</a> uses UTF-8.</p>
<p><b>See also</b> <a href="qtextdocumentwriter.html#codec">codec</a>().</p>


<h3 class="fn"><a name="setDevice" />QTextDocumentWriter.setDevice (<i>self</i>, <a href="qiodevice.html">QIODevice</a>&#160;<i>device</i>)</h3><p>Sets the writer's device to the <i>device</i> specified. If a
device has already been set, the old device is removed but
otherwise left unchanged.</p>
<p>If the device is not already open, <a href="qtextdocumentwriter.html">QTextDocumentWriter</a> will attempt to
open the device in <a href="qiodevice.html#OpenModeFlag-enum">QIODevice.WriteOnly</a> mode by
calling open().</p>
<p><b>Note:</b> This will not work for certain devices, such as
<a href="qprocess.html">QProcess</a>, <a href="qtcpsocket.html">QTcpSocket</a> and <a href="qudpsocket.html">QUdpSocket</a>, where some configuration is
required before the device can be opened.</p>
<p><b>See also</b> <a href="qtextdocumentwriter.html#device">device</a>() and <a href="qtextdocumentwriter.html#setFileName">setFileName</a>().</p>


<h3 class="fn"><a name="setFileName" />QTextDocumentWriter.setFileName (<i>self</i>, QString&#160;<i>fileName</i>)</h3><p>Sets the name of the file to be written to <i>fileName</i>.
Internally, <a href="qtextdocumentwriter.html">QTextDocumentWriter</a> will create a
<a href="qfile.html">QFile</a> and open it in <a href="qiodevice.html#OpenModeFlag-enum">QIODevice.WriteOnly</a> mode,
and use this file when writing the document.</p>
<p><b>See also</b> <a href="qtextdocumentwriter.html#fileName">fileName</a>() and <a href="qtextdocumentwriter.html#setDevice">setDevice</a>().</p>


<h3 class="fn"><a name="setFormat" />QTextDocumentWriter.setFormat (<i>self</i>, <a href="qbytearray.html">QByteArray</a>&#160;<i>format</i>)</h3><p>Sets the format used to write documents to the <i>format</i>
specified. <i>format</i> is a case insensitive text string. For
example:</p>
<pre class="cpp">
         <span class="type"><a href="qtextdocumentwriter.html">QTextDocumentWriter</a></span> writer;
         writer<span class="operator">.</span>setFormat(<span class="string">"odf"</span>); <span class="comment">// same as writer.setFormat("ODF");</span>
</pre>
<p>You can call <a href="qtextdocumentwriter.html#supportedDocumentFormats">supportedDocumentFormats</a>()
for the full list of formats <a href="qtextdocumentwriter.html">QTextDocumentWriter</a> supports.</p>
<p><b>See also</b> <a href="qtextdocumentwriter.html#format">format</a>().</p>


<h3 class="fn"><a name="supportedDocumentFormats" />list-of-QByteArray QTextDocumentWriter.supportedDocumentFormats ()</h3><p>Returns the list of document formats supported by <a href="qtextdocumentwriter.html">QTextDocumentWriter</a>.</p>
<p>By default, Qt can write the following formats:</p>
<table class="generic">
<thead>
<tr class="qt-style">
<th>Format</th>
<th>Description</th>
</tr>
</thead>
<tr class="odd" valign="top">
<td>plaintext</td>
<td>Plain text</td>
</tr>
<tr class="even" valign="top">
<td>HTML</td>
<td>HyperText Markup Language</td>
</tr>
<tr class="odd" valign="top">
<td>ODF</td>
<td>OpenDocument Format</td>
</tr>
</table>
<p><b>See also</b> <a href="qtextdocumentwriter.html#setFormat">setFormat</a>().</p>


<h3 class="fn"><a name="write" />bool QTextDocumentWriter.write (<i>self</i>, <a href="qtextdocument.html">QTextDocument</a>&#160;<i>document</i>)</h3><p>Writes the given <i>document</i> to the assigned device or file
and returns true if successful; otherwise returns false.</p>


<h3 class="fn"><a name="write-2" />bool QTextDocumentWriter.write (<i>self</i>, <a href="qtextdocumentfragment.html">QTextDocumentFragment</a>&#160;<i>fragment</i>)</h3><p>Writes the document fragment specified by <i>fragment</i> to the
assigned device or file and returns true if successful; otherwise
returns false.</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;snapshot-4.9.5-9eb6aac99275 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt&#160;4.8.3</td></tr></table></div></address></body></html>